
package fr.utt.lo02.projet;

import java.io.IOException;

public class Carte {

    public final static int PIC = 0;
    public final static int COEUR = 1;
    public final static int CARREAU = 2;
    public final static int TREFLE = 3;
    public final static int JOKER = 4;
    

    public final static int DEUX = 0;
    public final static int TROIS = 1;
    public final static int QUATRE = 2;
    public final static int CINQ = 3;
    public final static int SIX = 4;
    public final static int SEPT = 5;
    public final static int HUIT = 6;
    public final static int NEUF = 7;
    public final static int DIX = 8;
    public final static int VALET = 9;
    public final static int DAME = 10;
    public final static int ROI = 11;
    public final static int AS = 12;
    public final static int JOKER1=13;
    public final static int JOKER2=14;
    public final static int NUL=15;

    public final static String[] COULEURS = {"Pic", "Coeur", "Carreau","Trefle","Joker"};
    public final static String[] VALEURS = {"Deux","Trois","Quatre","Cinq","Six","Sept", "Huit", "Neuf", "Dix", "Valet", "Dame", "Roi", "As","Joker1","Joker2"};

    protected int couleur;
    protected int valeur;
    protected int points;

    public Carte (int valeur, int couleur) {
	this.couleur=couleur;
	this.valeur=valeur;
        switch(valeur){
            case 9:
                this.points=10;
                break;
            case 10:
                this.points=10;
                break;
            case 11:
                this.points=10;
                break;
            default:
               this.points=valeur+2;
                break;
        }
    }

    public Carte (String valeur, String couleur) {

	int i = 0;
	int c = 0, v = 0;
	boolean trouve = false;

	while (i < Carte.COULEURS.length && trouve == false) {
	    if (couleur.equals(Carte.COULEURS[i])) {
		trouve = true;
		c = i;
	    } else {
		i++;
	    }
	}

	i = 0;
	trouve = false;

	while (i < Carte.VALEURS.length && trouve == false) {
	    if (valeur.equals(Carte.VALEURS[i])) {
		trouve = true;
		v = i;
	    } else {
		i++;
	    }
	}

	this.couleur=c;
	this.valeur=v;
    }
    
    public void effet(Partie p, Joueur j)throws IOException{
    	System.out.println("Carte sans effet");
    }

    public int getCouleur() {
	return couleur;
    }

    public void setCouleur(int couleur) {
	if (couleur >= Carte.PIC && couleur <= Carte.JOKER) {
	    this.couleur = couleur;
	}
    }

    public int getValeur() {
	return valeur;
    }

    public void setValeur(int valeur) {
	if (valeur >= Carte.DEUX && valeur <= Carte.JOKER2) {
	    this.valeur = valeur;
	}
    }

    @Override
    public String toString() {
	StringBuffer sb = new StringBuffer();
	sb.append(Carte.VALEURS[this.valeur]);
	sb.append(" de ");
	sb.append(Carte.COULEURS[this.couleur]);
	return sb.toString();
    }

    /**
     * @return the points
     */
    public int getPoints() {
        return points;
    }

    /**
     * @param points the points to set
     */
    public void setPoints(int points) {
        this.points = points;
    }
}
